<?php
$smarty->configLoad($lang . '/petitions.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$_language = parse_ini_file($lang . '/petitions.module.php', true);
$breadcrumb = $language['petitions_detail'];

$sql = 'SELECT * FROM '.DB_GAME.'.petitions WHERE id = :id';
$dbh = $connection->prepare($sql);
$dbh->bindValue(':id', $_GET['id']); 
$dbh->execute();
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {

	if($row['status'] == 'PENDING') {
		$row['status'] = $_language['PENDING'];
	} elseif($row['status'] == 'REPLIED') {
		$row['status'] = $_language['REPLIED'];
	} elseif($row['status'] == 'IN_PROGRESS') {
		$row['status'] = $_language['IN_PROGRESS'];
	}
	$value[] = $row;
}
if(isset($_POST['progress'])) {
	$sql = 'UPDATE '.DB_GAME.'.petitions SET status = "IN_PROGRESS" WHERE id = :id';
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':id', $_GET['id']);
	$dbh->execute();
	$main->jqmodal('progress');
	echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=petitions&page=detail&id='.$_GET['id'].'">';

}
if(isset($_POST['close'])) {
	$sql = 'UPDATE '.DB_GAME.'.petitions SET status = "REPLIED" WHERE id = :id';
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':id', $_GET['id']);
	$dbh->execute();
	$main->jqmodal('closed');
	echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=petitions&page=detail&id='.$_GET['id'].'">';
}
$smarty->assign('value', $value);
$template = 'petitions/detail.tpl';
?>
